import http from "@/utils/http.ts";
import {Dict, R} from "@/api/common.ts";

export interface RootObject {
    time: string;
    type: number;
    param: Kriging | Idw;
}

export interface Kriging {
    alpha: number;
    sigma2: number;
    width: number;
    range: number;
    model: number;
    field: string;
}

export interface Idw {
    power: number;
    field: string;
    width: number;
    range: number;
    distance: number;
}

export interface DictMixed {
    type: Dict[];
    kriging: Dict[];
    idw: Dict[];
}

interface Base {
    width: number;
    type: number;
}

interface BaseIdw {
    distance: number;
    power: number;
}

interface BaseKriging {
    alpha: number;
    sigma2: number;
    model: number;
}

export type BaseMixed = Base & BaseIdw & BaseKriging

export function searchInterpolate(data: RootObject) {
    return http<R<null>>({
        url: "interpolate/search/kriging",
        method: "post",
        data: data
    })
}

export function searchInterpolateIdw(data: RootObject) {
    return http<R<null>>({
        url: "interpolate/search/idw",
        method: "post",
        data: data
    })
}

export function postIdwInterpolate(data: FormData) {
    return http<R<null>>({
        url: "interpolate/idw",
        method: "post",
        data: data
    })
}

export function getDict() {
    return http<R<DictMixed>>({
        url: "interpolate/dict",
        method: "get",
    })
}

export function postKrigingInterpolate(data: FormData) {
    return http<R<null>>({
        url: "interpolate/kriging",
        method: "post",
        data: data
    })
}